<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom title="收到的简历" :isAppBtn="false"></HeadCustom>
		<view v-if="listConfig.loading == 'not-data'"><NotEmpty text="暂未发布职位，无法匹配人才" btn="发布职位" @btn="goPage" /></view>
		<view class="card-box" v-else>
			<view class="card-hd">
				<NavFilter type="company" :companyId="companyId" :isMore="true" :isRecommend="false" @change="tabsClick" @not="notData" />
				<SearchCustom :keyword.sync="keyword" @search="getInit()" />
			</view>
			<view class="card-bd">
				<view v-if="listConfig.loading == 'list-not'"><NotEmpty :height="scrollHeight" /></view>
				<view v-if="listData.length || listConfig.loading == 'loading'">
					<scroll-view
						class="card-scroll"
						:scroll-top="scrollTop"
						scroll-y="true"
						:style="{ height: scrollHeight + 'px' }"
						@scrolltoupper="upper"
						@scrolltolower="lower"
						@scroll="scroll"
					>
						<view class="list">
							<!-- {{scrollHeight}} -->
							<view v-for="(item, index) in listData" :key="index"><VitaItem type="resumeReceived" :innerData="item" :jobId="jobId" /></view>
							<u-loadmore fontSize="24rpx" :status="listConfig.loading" />
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { orgReceiveList, companyDetail } from '@/api/recruit.js';
import VitaItem from '../components/vita-item.vue';
import NavFilter from '../components/nav-filter.vue';
import SearchCustom from '@/components/search/search-custom.vue';
import { listMixins } from '../common/list.mixins.js';
import { getRequest } from '@/static/js/common.js';
import { utf8to16, base64decode } from '@/static/js/Base64.js';
export default {
	mixins: [listMixins],
	components: { VitaItem, NavFilter, SearchCustom },
	data() {
		return {
			theme: getApp().globalData.appTheme,
			globalColor: getApp().globalData.globalColor,
			scrollTop: 0,
			listConfig: {
				current: 1,
				size: 20,
				count: 0,
				loading: 'loading'
			},
			listData: [],
			jobId: '',
			keyword: '',
			companyId: getApp().globalData.companyId,
			scrollHeight: 0,
			sys: {}
		};
	},
	onLoad(option) {
		const sys = uni.getSystemInfoSync();
		// alert(JSON.stringify(sys))
		if (option && option.companyId) {
			this.companyId = option.companyId;
		}
		if (option && option.benwu) {
			const benwu = utf8to16(base64decode(option.benwu));
			console.log(benwu);
			const token = {
				access_token: getRequest(benwu, 'token'),
				companyId: getRequest(benwu, 'companyId'),
				statusBarHeight: getRequest(benwu, 'statusBarHeight'),
				authStatus: getRequest(benwu, 'authStatus')
			};
			console.log(token);
			getApp().globalData.companyId = token.companyId;
			getApp().globalData.statusBarHeight = token.statusBarHeight;
			// getApp().globalData.companyAuthStatus = token.authStatus
			this.companyId = token.companyId;
			uni.setStorageSync('bw_params', JSON.stringify(token));
			this.getCompanyInfo();
		}
	},
	onShow() {
		if (this.jobId) {
			this.getInit();
		}
	},
	onReady() {
		this.getHeight('.head-custom-wrap,.nav-filter, .search-wrap');
	},
	methods: {
		getInit() {
			this.listConfig = {
				current: 1,
				size: 20,
				count: 0,
				loading: 'loading'
			};
			this.listData = [];
			this.getList();
		},
		getList() {
			const { current, size, loading } = this.listConfig;
			const { keyword, jobId, companyId } = this;
			orgReceiveList({ current, size, keyword, jobId, companyId }).then(res => {
				if (this.listData.length) {
					this.listData = this.listData.concat(res.data.list);
				} else {
					this.listData = res.data.list;
				}
				this.listLoading(res);
			});
		},
		getCompanyInfo() {
			companyDetail({ id: this.companyId }).then(res => {
				getApp().globalData.companyInfo = res.data;
				getApp().globalData.companyId = res.data.companyId;
				uni.setStorageSync('bw_company_info', JSON.stringify(res.data));
				// this.title = res.data.companyName
			});
		},
		tabsClick(e) {
			console.log(e);
			if (e) {
				this.jobId = e.jobId;
				this.getInit();
			} else {
				this.listConfig.loading = 'not-data';
			}
			// this.navIndex = e.index
		},
		notData() {
			this.listConfig.loading = 'not-data';
		},
		goPage() {
			this.$pageTo('/recruit/enterprise/publishRecruitment?companyId' + this.companyId);
		},
		upper(e) {
			console.log('upper', e);
		},
		lower(e) {
			console.log('lower', e);
			this.listMore();
		},
		scroll(e) {
			this.scrollTop = e.detail.scrollTop;
		},
		goTop(e) {
			// 解决view层不同步的问题
			this.scrollTop = this.old.scrollTop;
			this.$nextTick(function() {
				this.scrollTop = 0;
			});
			uni.showToast({
				icon: 'none',
				title: '纵向滚动 scrollTop 值已被修改为 0'
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.page-wrap {
	min-height: calc(100vh);
}
.card-box .card-hd {
}
.list {
	padding: 24rpx;
}
</style>
